<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Control Structures</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Control Structures' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../inbuildn.html">Inbuild Modules</a></li><li><a href="index.html">supervisor</a></li><li><a href="index.html#6">Chapter 6: Inform Source Text</a></li><li><b>Control Structures</b></li></ul></div>
<p class="purpose">To specify the syntax of control structures such as repeat, if and otherwise.</p>

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. </b>Certain phrases are "control structures": otherwise, if, repeat, while and
so on. These have different expectations in terms of the layout of surrounding
phrases in rule or phrase definitions, and the following structure defines
the relevant behaviour. (The contents are static.)
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax"> *</span><span class="identifier-syntax">subordinate_to</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">mnemonic</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">indent_subblocks</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">body_empty_except_for_subordinates</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">used_at_stage</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">is_a_loop</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">requires_new_syntax</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">allow_run_on</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inchar32_t</span><span class="plain-syntax"> *</span><span class="identifier-syntax">keyword</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure control_structure_phrase is private to this section.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax"> *</span><span class="function-syntax">ControlStructures::new</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">ControlStructures::new</span></span>:<br/><a href="6-cs.html#SP5">&#167;5</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">mnemonic</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax"> *</span><span class="identifier-syntax">csp</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">csp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">mnemonic</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::duplicate</span><span class="plain-syntax">(</span><span class="identifier-syntax">mnemonic</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">csp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">subordinate_to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">csp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">indent_subblocks</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">csp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">body_empty_except_for_subordinates</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">csp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used_at_stage</span><span class="plain-syntax"> = -1;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">csp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">requires_new_syntax</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">csp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">allow_run_on</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">csp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">keyword</span><span class="plain-syntax"> = </span><span class="identifier-syntax">U</span><span class="string-syntax">"&lt;none&gt;"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">csp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">is_a_loop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">csp</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>Some cryptic mnemonics for logging the invocation tree:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">ControlStructures::log</span><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax"> *</span><span class="identifier-syntax">csp</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">csp</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"---"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"%S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">csp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">mnemonic</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>The following set is built in to the Inform language; Basic Inform and such
extensions cannot extend it.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax"> *</span><span class="identifier-syntax">switch_CSP</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, *</span><span class="identifier-syntax">if_CSP</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, *</span><span class="identifier-syntax">repeat_CSP</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    *</span><span class="identifier-syntax">while_CSP</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, *</span><span class="identifier-syntax">otherwise_CSP</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, *</span><span class="identifier-syntax">abbreviated_otherwise_CSP</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    *</span><span class="identifier-syntax">otherwise_if_CSP</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, *</span><span class="identifier-syntax">default_case_CSP</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, *</span><span class="identifier-syntax">case_CSP</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    *</span><span class="identifier-syntax">say_CSP</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, *</span><span class="identifier-syntax">instead_CSP</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>And this is where they are all created:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">ControlStructures::create_standard</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">ControlStructures::create_standard</span></span>:<br/>Inbuild Control - <a href="1-ic.html#SP5">&#167;5</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">switch_CSP</span><span class="plain-syntax"> = </span><a href="6-cs.html#SP2" class="function-link"><span class="function-syntax">ControlStructures::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"SWI"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">switch_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">body_empty_except_for_subordinates</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">switch_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">indent_subblocks</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">switch_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">requires_new_syntax</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">switch_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">keyword</span><span class="plain-syntax"> = </span><span class="identifier-syntax">U</span><span class="string-syntax">"if"</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">if_CSP</span><span class="plain-syntax"> = </span><a href="6-cs.html#SP2" class="function-link"><span class="function-syntax">ControlStructures::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"IF"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">if_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">keyword</span><span class="plain-syntax"> = </span><span class="identifier-syntax">U</span><span class="string-syntax">"if"</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">repeat_CSP</span><span class="plain-syntax"> = </span><a href="6-cs.html#SP2" class="function-link"><span class="function-syntax">ControlStructures::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"RPT"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">repeat_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">keyword</span><span class="plain-syntax"> = </span><span class="identifier-syntax">U</span><span class="string-syntax">"repeat"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">repeat_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">is_a_loop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">while_CSP</span><span class="plain-syntax"> = </span><a href="6-cs.html#SP2" class="function-link"><span class="function-syntax">ControlStructures::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"WHI"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">while_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">keyword</span><span class="plain-syntax"> = </span><span class="identifier-syntax">U</span><span class="string-syntax">"while"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">while_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">is_a_loop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">otherwise_CSP</span><span class="plain-syntax"> = </span><a href="6-cs.html#SP2" class="function-link"><span class="function-syntax">ControlStructures::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"O"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">otherwise_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">subordinate_to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">if_CSP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">otherwise_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used_at_stage</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">abbreviated_otherwise_CSP</span><span class="plain-syntax"> = </span><a href="6-cs.html#SP2" class="function-link"><span class="function-syntax">ControlStructures::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"AO"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">abbreviated_otherwise_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">subordinate_to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">if_CSP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">abbreviated_otherwise_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used_at_stage</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">otherwise_if_CSP</span><span class="plain-syntax"> = </span><a href="6-cs.html#SP2" class="function-link"><span class="function-syntax">ControlStructures::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"OIF"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">otherwise_if_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">subordinate_to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">if_CSP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">otherwise_if_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used_at_stage</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">case_CSP</span><span class="plain-syntax"> = </span><a href="6-cs.html#SP2" class="function-link"><span class="function-syntax">ControlStructures::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"CAS"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">case_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">subordinate_to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">switch_CSP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">case_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used_at_stage</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">case_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">requires_new_syntax</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">case_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">allow_run_on</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">default_case_CSP</span><span class="plain-syntax"> = </span><a href="6-cs.html#SP2" class="function-link"><span class="function-syntax">ControlStructures::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"DEF"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">default_case_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">subordinate_to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">switch_CSP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">default_case_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used_at_stage</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">default_case_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">requires_new_syntax</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">default_case_CSP</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">allow_run_on</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">say_CSP</span><span class="plain-syntax"> = </span><a href="6-cs.html#SP2" class="function-link"><span class="function-syntax">ControlStructures::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"SAY"</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">instead_CSP</span><span class="plain-syntax"> = </span><a href="6-cs.html#SP2" class="function-link"><span class="function-syntax">ControlStructures::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"INS"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>Control structures such as "if" act as a sort of super-punctuation inside
rule and phrase definitions, and in particular they affect the actual
punctuation of the sentences there (consider the rules about colons versus
semicolons). So, though it's still early in Inform's run, we need to seek
them out.
</p>

<p class="commentary">Here we parse the text of a command phrase which, if any, of the control
structures it might be. Note that &lt;s-command&gt; has a grammar partially
overlapping with this, and they need to match.
</p>

<p class="commentary">At one time we handled "now" as a control structure, but have rowed back
on that: it's possible to implement it as a regular phrase (at the cost of
introducing a complication to how its one token is invoked), and that seems
better. See Jira bug report I7-2317.
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">NO_SIGF</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">SAY_SIGF</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;control-structure-phrase&gt;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ... </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">begin</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ... </span><span class="identifier-syntax">is</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax">/</span><span class="identifier-syntax">unless</span><span class="plain-syntax"> ... |</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">repeat</span><span class="plain-syntax"> ... |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> ... |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax">/</span><span class="identifier-syntax">otherwise</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax">/</span><span class="identifier-syntax">otherwise</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax">/</span><span class="identifier-syntax">unless</span><span class="plain-syntax"> ... |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax">/</span><span class="identifier-syntax">otherwise</span><span class="plain-syntax"> ... |</span>
<span class="plain-syntax">    -- </span><span class="identifier-syntax">otherwise</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    -- ...</span>

<span class="function-syntax">&lt;end-control-structure-phrase&gt;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">end</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax">/</span><span class="identifier-syntax">unless</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">end</span><span class="plain-syntax"> </span><span class="reserved-syntax">while</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">end</span><span class="plain-syntax"> </span><span class="identifier-syntax">repeat</span>

<span class="function-syntax">&lt;other-significant-phrase&gt;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">say</span><span class="plain-syntax"> ...</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>This is used to see if an "if" is being used with the comma notation:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;phrase-with-comma-notation&gt;</span>
<span class="plain-syntax">    ...... , ......</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b>This is used to see if an "if" is being used with the comma notation:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;instead-keyword&gt;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">instead</span><span class="plain-syntax"> ... |</span>
<span class="plain-syntax">    ... </span><span class="identifier-syntax">instead</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. </b>Finally, this is used to see if a control structure opens a block:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;phrase-beginning-block&gt;</span>
<span class="plain-syntax">    ... </span><span class="identifier-syntax">begin</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. </b>And some miscellaneous provisions:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">ControlStructures::comma_possible</span><span class="plain-syntax">(</span><span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax"> *</span><span class="identifier-syntax">csp</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">csp</span><span class="plain-syntax"> == </span><span class="identifier-syntax">if_CSP</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">csp</span><span class="plain-syntax"> == </span><span class="identifier-syntax">switch_CSP</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">csp</span><span class="plain-syntax"> == </span><span class="identifier-syntax">otherwise_if_CSP</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">ControlStructures::is_a_loop</span><span class="plain-syntax">(</span><span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax"> *</span><span class="identifier-syntax">csp</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">csp</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">csp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">is_a_loop</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">ControlStructures::opens_block</span><span class="plain-syntax">(</span><span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax"> *</span><span class="identifier-syntax">csp</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">csp</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">csp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">subordinate_to</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">csp</span><span class="plain-syntax"> != </span><span class="identifier-syntax">say_CSP</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">csp</span><span class="plain-syntax"> != </span><span class="identifier-syntax">instead_CSP</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">ControlStructures::permits_break</span><span class="plain-syntax">(</span><span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax"> *</span><span class="identifier-syntax">csp</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">csp</span><span class="plain-syntax"> == </span><span class="identifier-syntax">repeat_CSP</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">csp</span><span class="plain-syntax"> == </span><span class="identifier-syntax">while_CSP</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="identifier-syntax">inchar32_t</span><span class="plain-syntax"> *</span><span class="function-syntax">ControlStructures::incipit</span><span class="plain-syntax">(</span><span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax"> *</span><span class="identifier-syntax">csp</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">csp</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">csp</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">keyword</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">U</span><span class="string-syntax">"&lt;none&gt;"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax"> *</span><span class="function-syntax">ControlStructures::detect</span><span class="plain-syntax">(</span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;control-structure-phrase&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;&lt;rp&gt;&gt;</span><span class="plain-syntax"> == </span><span class="identifier-syntax">abbreviated_otherwise_CSP</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;&lt;rp&gt;&gt;</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">ControlStructures::abbreviated_otherwise</span><span class="plain-syntax">(</span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;control-structure-phrase&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;&lt;rp&gt;&gt;</span><span class="plain-syntax"> == </span><span class="identifier-syntax">abbreviated_otherwise_CSP</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">control_structure_phrase</span><span class="plain-syntax"> *</span><span class="function-syntax">ControlStructures::detect_end</span><span class="plain-syntax">(</span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;end-control-structure-phrase&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;&lt;rp&gt;&gt;</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="6-inc.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-sm.html">1</a></li><li class="progresschapter"><a href="2-gnr.html">2</a></li><li class="progresschapter"><a href="3-bg.html">3</a></li><li class="progresschapter"><a href="4-em.html">4</a></li><li class="progresschapter"><a href="5-es.html">5</a></li><li class="progresscurrentchapter">6</li><li class="progresssection"><a href="6-st.html">st</a></li><li class="progresssection"><a href="6-hdn.html">hdn</a></li><li class="progresssection"><a href="6-tof.html">tof</a></li><li class="progresssection"><a href="6-inc.html">inc</a></li><li class="progresscurrent">cs</li><li class="progresssection"><a href="6-vmg.html">vmg</a></li><li class="progresschapter"><a href="7-tm.html">7</a></li><li class="progressnext"><a href="6-vmg.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

